package www.game.pay;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class demo {
    public static void main(String[] args) {
        String url = "jdbc:mysql://127.0.0.1:3306/gameplatform";
        String user = "root";
        String password = "123456";

        // 添加驱动加载
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            System.out.println("❌ MySQL驱动未找到");
            e.printStackTrace();
            return;
        }

        try (Connection connection = DriverManager.getConnection(url, user, password)) {
            System.out.println("✅ 数据库连接成功！");

            // 可以在这里添加测试查询
            var statement = connection.createStatement();
            var resultSet = statement.executeQuery("SELECT 1 as test");
            if (resultSet.next()) {
                System.out.println("✅ 测试查询成功，返回: " + resultSet.getInt("test"));
            }

        } catch (SQLException e) {
            System.out.println("❌ 数据库连接失败: " + e.getMessage());
            e.printStackTrace();
        }


    }

    public static Connection getConnection() {
        String url = "jdbc:mysql://127.0.0.1:3306/gameplatform";
        String user = "root";
        String password = "123456";

        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            return DriverManager.getConnection(url, user, password);
        } catch (Exception e) {
            System.out.println("连接失败: " + e.getMessage());
            return null;
        }
    }


}